import java.util.Scanner;

class A implements Cloneable{
    @Override
    protected Object
    clone() throws CloneNotSupportedException {
        return super.clone();
    }
}

public class Test {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        try {
            System.out.println(10/a);
        }catch (ArithmeticException e) {
            e.printStackTrace();
            System.out.println("捕获到了算术异常！");
        }finally {
            scanner.close();
            System.out.println("finally，不管是否抛出异常，都被执行了");
        }
        System.out.println("其他业务代码也会被执行");
    }


    public static void main2(String[] args) {
        int a = 0;
        try {
            System.out.println(10/a);

            int[] array = null;
            System.out.println(array.length);
            //程序既然已经发生异常了 说明这个业务是有问题的 所以下面的代码将不会被执行
            System.out.println("12334");

        }/*catch (ArithmeticException | NullPointerException e) {
            System.out.println("捕获到了异常！");
        }*/
        catch (ArithmeticException e) {
            e.printStackTrace();//打印栈上的异常信息
            System.out.println("捕获到了算术异常！");
        }catch (NullPointerException e) {
            System.out.println("捕获空指针异常！");
        } catch (Exception e) {//把父类放到最后
            System.out.println("捕获到了异常！");
        }
        System.out.println("其他业务代码");
}




    //throws CloneNotSupportedException 一般放在方法的声明的地方
    public static void test()throws CloneNotSupportedException {
        int a = 0;
        if(a == 0) {
            //抛出一个自定义的异常！
            throw new CloneNotSupportedException("a == 0");
        }
    }
    public static void main1(String[] args) throws CloneNotSupportedException {
        //算数异常
        System.out.println(10 / 0);

        //数组越界异常
        int[] arr1 = {1, 2, 3};
        System.out.println(arr1[100]);


        //空指针异常
        int[] arr2 = null;
        System.out.println(arr2.length);

        A a = new A();
        A a1 = (A)a.clone();
    }
}
